<?php
defined('BASEPATH') or exit('No direct script access allowed');
session_start();

class Dashboard extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->helper("url");
        $this->load->model("dashboard_model");
        $this->load->model("subscription_model");
        $this->load->helper('path');
    }

    public function index()
    {
        if (isset($_SESSION["user"])) {
            $data["title"] = "主页";

            $row = $this->dashboard_model->getAll();
            $data['dashboard'] = $row;

            $tasks = $this->subscription_model->getTask();
            $data["tasks"] = $tasks;

            $user = $_SESSION["user"];
            $data["nickname"] = $user["nickname"];

            $this->load->view("templates/header", $data);
            $this->load->view("dashboard/dashboard", $data);
            $this->load->view("templates/footer");
        } else {
            redirect("login");
        }

    }

    public function start()
    {
        $cmd = "/var/www/html/website/py.sh";
        exec("nohup sudo ".$cmd." >/dev/null 2>&1 &");
        redirect('dashboard');
    }
}

?>